package com.jinglvhuanjing.app.widget;

import android.content.Context;
import android.util.AttributeSet;
import android.view.Gravity;
import android.view.LayoutInflater;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.widget.LinearLayoutCompat;

import com.jinglvhuanjing.app.R;
import com.jinglvhuanjing.app.bean.param.ParamLayout1Bean;
import com.jinglvhuanjing.app.utils.Constants;
import com.jinglvhuanjing.app.utils.SpUtils;

import java.util.ArrayList;
import java.util.HashMap;

public class ParamSettingRow1View extends LinearLayoutCompat {

    public ParamSettingRow1View(@NonNull Context context) {
        super(context);
        this.init(context);
    }

    public ParamSettingRow1View(@NonNull Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        this.init(context);
    }

    public ParamSettingRow1View(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        this.init(context);
    }

    /*** 分类站编号 ***/
    private CustomEdtView flzbh;
    /*** 网路通信状态 ***/
    private CustomTextView wltxzt;
    /*** 服务器IP ***/
    private CustomEdtView fwqip;
    /*** 数据传输间隔 ***/
    private CustomEdtView sjcsjg;

    private void init(Context context) {
        setGravity(Gravity.CENTER_VERTICAL);
        LayoutInflater.from(context).inflate(R.layout.view_params_setting_row_1_layout, this, true);
        this.flzbh = findViewById(R.id.flzbh);
        this.wltxzt = findViewById(R.id.wltxzt);
        this.fwqip = findViewById(R.id.fwqip);
        this.sjcsjg = findViewById(R.id.sjcsjg);

        this.flzbh.setParamTag("分类站编号", Constants.DEVICE_ID);
        this.wltxzt.setParamTag("网路通信状态", ParamLayout1Bean.PARAM_KEY_WLTXZT);
        this.fwqip.setParamTag("服务器IP", Constants.SERVER_IP);
        this.sjcsjg.setParamTag("数据传输间隔", Constants.INTERVAL_TIME);

        this.initEvent();
        this.initData();
    }

    /**
     * 获取值
     *
     * @return 集合
     */
    public ArrayList<HashMap<String, String>> getFormValue() {
        ArrayList<HashMap<String, String>> values = new ArrayList<>();
        values.add(this.flzbh.getValueMap());
        values.add(this.wltxzt.getValueMap());
        values.add(this.fwqip.getValueMap());
        values.add(this.sjcsjg.getValueMap());
        return values;
    }

    private void initEvent() {

    }

    private void initData() {
        // 分类站编号
        flzbh.setText("" + SpUtils.getString(getContext(), Constants.DEVICE_ID));
        // 服务器IP
        fwqip.setText("" + SpUtils.getString(getContext(), Constants.SERVER_IP));
        // 数据传输间隔
        sjcsjg.setText("" + SpUtils.getString(getContext(), Constants.INTERVAL_TIME));
    }

}
